<?php
/******************************************************
v4 - Management Framework
Copyright (C) 2008  Gary Taylor, gMerc Incorporation
http://www.gmerc.com/v4/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

gary@gmerc.com
******************************************************/
class saveinvoice_pdf {
  function loaddata() {
    global $masterclass;

    $masterclass->loadmodule('customers');
    $masterclass->loadmodule('personnel');
    $masterclass->loadmodule('invoices');
    $masterclass->loadmodule('paperpdf');

    $masterclass->loadmodule('paperpdf_render',$masterclass->mainconfig['v4moduledir'].'paperpdf/paperpdf_render.func.php');
  return;
  }
  function display() {
    global $masterclass;

    if ($masterclass->sitevars['invoices_documentdate']=='0000-00-00') { $masterclass->sitevars['invoices_documentdate']=date("Y/m/d"); } else { $masterclass->sitevars['invoices_documentdate']=date("Y/m/d",strtotime($masterclass->sitevars['invoices_documentdate'])); }
    if ($masterclass->sitevars['invoices_duedate']=='0000-00-00') { $masterclass->sitevars['invoices_duedate']=''; } else { $masterclass->sitevars['invoices_duedate']=date("Y/m/d",strtotime($masterclass->sitevars['invoices_duedate'])); }

    $strwhere=sprintf(" (`id`=%d) ",$masterclass->allclasses['mysql_functions']->formatmysqldbl($masterclass->sitevars['invoicesid']));
    $invoicesinfo=$masterclass->fetch_records('`invoices_documents`',1,$strwhere,'','*');
    $invoicesitems=$masterclass->allclasses['invoices']->fetch_invoices_items($masterclass->sitevars['invoicesid'],'',' `datestamp` ');

    $masterclass->sitevars['pdfdata']=array();
    $masterclass->sitevars['pdfdata']['pdfname']='invoice_'.$invoicesinfo->fields['documentid'].'.pdf';
    $masterclass->sitevars['pdfdata']['pdfforms'][]=array('pdflibrary'=>'pdf_invoice','pdflibrary_path'=>$masterclass->mainconfig['v4moduledir'].'invoices/pdf_forms/pdf_invoice.lib.php','pdfdata'=>array('invoiceinfo'=>$invoicesinfo,'invoiceitems'=>$invoicesitems));

    $masterclass->allclasses['paperpdf_render']->render_document('D');
  return;
  }
}
?>